.main-toolbar.toolbar
  = link_to t("labels.delete_x_entries", count: @invalid_entries_count), { controller: :invalid_journal_entries, action: :delete_all }, { class: 'btn btn-default no-icn', data: { confirm: :are_you_sure.tl } }
.meta-toolbar.toolbar
  %span.list-pagination{data:{list_ref: "items-list"}}
    - limit = 20
    - current_page = @invalid_entries.current_page
    - pages_count = @invalid_entries.total_pages
    - count = @invalid_entries_count
    - x = limit * (current_page - 1) + 1
    - y = (current_page < pages_count) ? current_page * limit : count
    %span.status= 'list.pagination.x_to_y_of_total'.t(x: x, y: y, total: count)
    %span.paginator
      %a{href: list_backend_invalid_journal_entries_path(page: current_page - 1), class: [("btn previous-page"),("disabled" if current_page == 1)], data: {remote: :true}}
        %i
      %a{href: list_backend_invalid_journal_entries_path(page: current_page + 1), class: [("btn next-page"),("disabled" if current_page == @invalid_entries.total_pages)], data: {remote: :true}}
        %i
%table
  %thead
    - currency = Preference[:currency]
    %th.act
      %i.icon.icon-edit
    %th.act
      %i.icon.icon-destroy
    %th= Journal.name
    %th= JournalEntryItem.human_attribute_name(:entry_number)
    %th= JournalEntryItem.human_attribute_name(:printed_on)
    %th= JournalEntryItem.human_attribute_name(:account)
    %th= JournalEntryItem.human_attribute_name(:name)
    %th.right-align= JournalEntryItem.human_attribute_name(:debit)
    %th.right-align= JournalEntryItem.human_attribute_name(:credit)
  %tbody.first-item
    - @invalid_entries.each do |entry|
      - entry.items.each do |item|
        - first_item = (entry.items.first === item)
        %tr{class: ("first-item" if first_item) }
          %td.act= link_to("<i class='icon icon-edit'></i>".html_safe, edit_backend_journal_entry_path(entry), class: "edit") if first_item
          %td.act= link_to("<i class='icon icon-destroy'></i>".html_safe, backend_journal_entry_path(entry), method: :delete, class: "destroy") if first_item
          %td= link_to(entry.journal.name, { controller: :journals, action: :show, id: entry.journal.id} ) if first_item
          %td= link_to(entry.number, { controller: :journal_entry_items, action: :show, id: item.id} ) if first_item
          %td= entry.printed_on.strftime("%d/%m/%Y") if first_item
          %td= link_to(item.account_label, { controller: :accounts, action: :show, id: item.account.id})
          %td= truncate(item.name, length: 50)
          %td.right-align= number_to_accountancy(item.debit, currency, false)
          %td.right-align= number_to_accountancy(item.credit, currency, false)
